#!/bin/bash

# ----------------------------------------------------------------------
# Filename:   75637-ls.sh
# Version:    1.0
# Date:       2013/12/18
# Author:     yuanhui.shi
# Email:      yuanhui.shi@cs2c.com.cn
# Summary:    03系统安全功能-01SELinux-03SELinux重要命令-03SELinux安全上下文标签相关命令-01ls(dir/vdir)
# Notes:      安全上下文标签 ls
# Copyright:  China Standard Software Co., Ltd.
# History：     
#             Version 1.0, 2013/12/18
#             -   The first one
# ----------------------------------------------------------------------

PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH

source ../../lib/Echo.sh
source ../../lib/XmlParse.sh
source ./lib/Selib.sh

function CleanData ()
{
  rm -rf /tmp/test 
  EchoInfo "75637-ls.sh执行完毕"
}

trap "CleanData" EXIT
CheckSElinuxStatus

mkdir /tmp/test
mkdir /tmp/test/dir1
touch /tmp/test/file1

EchoInfo "ls --lcontext：以较长格式显示当前目录下文件安全上下文信息及其他信息，现在检验执行结果是否正确"
[ "`ls --lcontext /tmp/test/file1|awk '{print$10}'`" == "/tmp/test/file1" ] && [ "`ls --lcontext /tmp/test/dir1 -d |awk '{print$10}'`" == "/tmp/test/dir1" ]
EchoResult "ls --lcontext命令执行结果正确"

EchoInfo "ls --context：仅显示文件类型、用户、组及安全上下文信息"
[ "`ls --context /tmp/test/file1|cut -d " " -f5`" == "/tmp/test/file1" ] && [ "`ls --context /tmp/test/dir1 -d |cut -d " " -f5`" == "/tmp/test/dir1" ]
EchoResult "ls --context命令执行结果正确"

EchoInfo "ls -Z：仅显示文件类型、用户、组及安全上下文信息"
[ "`ls -Z /tmp/test/file1|cut -d " " -f5`" == "/tmp/test/file1" ] && [ "`ls -Z /tmp/test/dir1 -d |cut -d " " -f5`" == "/tmp/test/dir1" ]
EchoResult "ls -Z命令执行结果正确"

EchoInfo "ls --scontext：仅显示当前目录下安全上下文信息"
[ "`ls --scontext /tmp/test/file1|cut -d " " -f2`" == "/tmp/test/file1" ] && [ "`ls --scontext /tmp/test/dir1 -d |cut -d " " -f2`" == "/tmp/test/dir1" ]
EchoResult "ls --scontext命令执行结果正确"

